from pathlib import Path

from utils import Base, read_file

class Prompt:
    def __init__(self, template, name):
        self.name = name
        self.template = template

    def __call__(self, *args, **kwargs):
        return self.template.format(*args, **kwargs)


class Prompts(Base):
    def __init__(self, version):
        super().__init__()
        self.prompts = {}
        self.version = version
        self.load_prompt()

    def __getattr__(self, key):
        return self.prompts.get(key)

    def __getitem__(self, key):
        return self.prompts.get(key)

    def _load_prompt(self, prompts, part):
        prompt_path = Path(self.base_path).resolve()
        prompt_path = prompt_path / "prompts" / "prompt" / part / self.version
        for key, value in prompts.items():
            prompt = read_file(prompt_path / value)
            self.prompts[key] = Prompt(prompt, key)

    def load_prompt(self):
        raise NotImplementedError


class TranslatePrompt(Prompts):

    def load_prompt(self):
        prompts = {
            'function': 'function.txt',
            'struct': 'struct.txt',
            'global': 'global.txt',
        }
        part = 'translate'
        self._load_prompt(prompts, part)

class FixPrompt(Prompts):

    def load_prompt(self):
        prompts = {
            'fix': 'fix.txt'
        }
        part = 'fix'
        self._load_prompt(prompts, part)

if __name__ == '__main__':
    a = TranslatePrompt('version1')
    p = a.function
    print(p(1,2,3,4,5))